package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.Gathering;
import cn.wolfcode.crm.domain.Officialstu;
import cn.wolfcode.crm.domain.Refund;
import cn.wolfcode.crm.mapper.GatheringMapper;
import cn.wolfcode.crm.mapper.LeaveStudentMapper;
import cn.wolfcode.crm.mapper.RefundMapper;
import cn.wolfcode.crm.query.QueryForObject;
import cn.wolfcode.crm.service.IRefundService;
import cn.wolfcode.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * Created by Heroes on 2018/7/14.
 */
@Service
public class RefundServiceImpl implements IRefundService {

    @Autowired
    private RefundMapper mapper;
    @Autowired
    private LeaveStudentMapper leaveStudentMapper;

    @Override
    public void insert(Refund record) {
        record.setRefundTime(new Date());
        mapper.insert(record);
    }

    @Override
    public void deleteByPrimaryKey(Long id) {
        mapper.deleteByPrimaryKey(id);
    }

    @Override
    public void updateByPrimaryKey(Refund record) {

    }

    @Override
    public Refund selectByPrimaryKey(Long id) {
        return mapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Refund> selectAll() {
        return mapper.selectAll();
    }

    //分页
    @Override
    public PageResult query(QueryForObject qo) {
        int total = mapper.queryForCount(qo);
        if (total == 0) {
            return new PageResult();
        }
        List<Refund> rows = mapper.queryForList(qo);

        return new PageResult(total, rows);
    }

    /**
     * 审核
     */
    @Override
    public void changeState(Long feeId,Long stuId) {
        mapper.changeState(feeId);
        leaveStudentMapper.changeRefundState(stuId);
    }

}
